<?php 
require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
require_once($_SERVER['DOCUMENT_ROOT']."/Modules/MF93FL27/modconf.mex");
MYTCONN();
$RSGET = $GLOBALS['MYT']->db_array("SELECT bonusinvoice.REF AS O_ID,
											INVOICE AS COL1,
											OriNombre AS COL2,
											CLIENT AS COL3,
											bns_Time AS COL4,
											main_users.name AS COL5,
											stt_Word AS COL6,
											bns_Value AS COL7,
											bni_Name AS COL8
						 FROM bonusinvoice
						INNER JOIN origenes ON bns_Origen1 = OriNumero
						INNER JOIN bns_invoicetypes ON bni_ID = bns_Type
						INNER JOIN systemoffice.main_users ON main_users.ref = bns_User
						INNER JOIN hd_sysstatus ON sttFlag = bns_Status AND stt_Sistema = 21
						 WHERE bns_Type IN (4,5) AND bns_Time BETWEEN '{$_POST['TStart']}' AND '{$_POST['TEnd']}'");
	$CARD = $RSGET[0];
	$total = 0; ?>
<script charset="utf-8" type="text/javascript">
disableSelection(document.getElementById("BenefictPanel"));

Ext.onReady(function(){

    Ext.QuickTips.init();

    var myData = [
	<?php   
	for ($i=1;$i<=$CARD;$i++) { 
	$total += $RSGET[$i]['COL7'];
	echo '['.$i.','.$RSGET[$i]['O_ID'].',\''.$RSGET[$i]['COL1'].'\',\''.$RSGET[$i]['COL2'].'\',\''.$RSGET[$i]['COL3'].'\',\''.$RSGET[$i]['COL4'].'\',\''.$RSGET[$i]['COL5'].'\',\''.$RSGET[$i]['COL6'].'\',\''.$RSGET[$i]['COL7'].'\',\''.$RSGET[$i]['COL8'].'\']';
		if ($i<$CARD) {
			echo ',';
		}
    } ?>
    ];

    var ds = new Ext.data.Store({
        reader: new Ext.data.ArrayReader({}, [
               {name: 'id'},
			   {name: 'O_ID', type: 'int'},
               {name: 'COL1', type: 'string'},
               {name: 'COL2', type: 'string'},
               {name: 'COL3', type: 'string'},
			   {name: 'COL4', type: 'string'},
               {name: 'COL5', type: 'string'},
               {name: 'COL6', type: 'string'},
               {name: 'COL7', type: 'string'},
               {name: 'COL8', type: 'string'}
          ])
    });
    ds.loadData(myData);
    var colModel = new Ext.grid.ColumnModel([
        {header: "Numero", width: 60, sortable: true, locked:true, dataIndex: 'O_ID'},
        {header: "Nr", width: 50, sortable: true, locked:true, dataIndex: 'COL1'},
        {header: "Loja", width: 200, sortable: true, dataIndex: 'COL2'},
        {header: "Tipo", width: 150, sortable: true, dataIndex: 'COL8'},
        {header: "Cliente", width: 100, sortable: true, locked:true,dataIndex: 'COL3'},
        {header: "Data", width: 120, sortable: true, locked:true,dataIndex: 'COL4'},
        {header: "Funcionario", width: 120, sortable: true, locked:true,dataIndex: 'COL5'},
        {header: "Estado", width: 75, sortable: true, locked:true,dataIndex: 'COL6'},
        {header: "Valor", width: 75, sortable: true, locked:true,dataIndex: 'COL7'}
    ]);
	
	Bars = new Ext.Toolbar({ 
				
					store: this.store, 
					height: 20,
					items : [ {
						text: "Total de valor em cheques: <?php echo number_format($total,2);?> EUR"
				}]
			});
   var selmode = new Ext.grid.RowSelectionModel({});
   var Console = new Ext.grid.GridPanel({

	    ds: ds,
	    cm: colModel,
	    sm: selmode,
		bbar: Bars,
		listeners: {
	 		rowdblclick: function(ds, row) { 
				var record = ds.getStore().getAt(row);
  				var value = record.get('O_ID');	
				modalwindow(value);
			}
		},
	    height: 420,
        renderTo: 'BenefictPanel'
    });
		
});
</script>